import { mpRequest } from "@/utils/request";
import { IArticalReviewReq, IMissionRecordReq } from "./types/knowledge";
import { IPage } from "./types";

/**
 * 知识分类
 */
export const apiQueryArticleCategory = () => {
  return mpRequest({
    url: "/article/category",
    method: "get",
  });
};

/**
 * 查询知识
 */
export const apiQueryArtickeById = (id: number, page: IPage) => {
  return mpRequest({
    url: `/article/category/${id}`,
    method: "get",
    params: page,
  });
};

/**
 * 点赞
 */
export const apiLikeArticle = (id: number) => {
  return mpRequest({
    url: `article/like/${id}`,
    method: "post",
  });
};

/**
 * 取消点赞
 */
export const apiCancelLikeArticle = (id: number) => {
  return mpRequest({
    url: `article/like/${id}`,
    method: "delete",
  });
};

/**
 * 收藏
 */
export const apiCollectArticle = (id: number) => {
  return mpRequest({
    url: `article/like/${id}`,
    method: "post",
  });
};

/**
 * 取消收藏
 */
export const apiCancelCollectArticle = (id: number) => {
  return mpRequest({
    url: `article/like/${id}`,
    method: "delete",
  });
};

/**
 * 获取我的收藏
 */
export const apiQuerySelftCollectArticle = () => {
  return mpRequest({
    url: `article/collect/self`,
    method: "get",
  });
};

/**
 * 分享文章
 */
export const apiShareArticle = (id: number) => {
  return mpRequest({
    url: `/article/share/${id}`,
    method: "post",
  });
};

/**
 * 完成任务
 */
export const apiAchieveMission = (data: IMissionRecordReq) => {
  return mpRequest({
    url: `/mission/record`,
    method: "post",
    data,
  });
};

/**
 * 根据名称查询文章
 */
export const apiQueryArticalByName = (name: string) => {
  return mpRequest({
    url: `/article/query/name`,
    method: "get",
    params: { name },
  });
};

/**
 * 获取我的收藏
 */
export const apiQueryMyCollectArticle = () => {
  return mpRequest({
    url: "/article/collect/self",
    method: "get",
  });
};

/**
 * 获取我的任务
 */
export const apiQuerySelfMission = () => {
  return mpRequest({
    url: "/mission/self",
    method: "get",
  });
};

/**
 * 获取分类列表
 */
export const apiQueryCaterogy = () => {
  return mpRequest({
    url: "/category",
    method: "get",
  });
};

/**
 * 获取分类文章
 */
export const apiQueryCatalogById = (categoryId: number) => {
  return mpRequest({
    url: "/catalog",
    method: "get",
    params: { categoryId },
  });
};

/**
 * 根据分类id获取文章内容
 */
export const apiQueryArticalContentById = (categoryId: number) => {
  return mpRequest({
    url: `/knowledge/category/${categoryId}`,
    method: "get",
  });
};

export const apiQueryCatalogProgress = (categoryId: number) => {
  return mpRequest({
    url: `/mission/catalog/${categoryId}`,
    method: "get",
  });
};

export const apiArticalReview = (id: number, data: IArticalReviewReq) => {
  return mpRequest({
    url: `/article/review/${id}`,
    method: "post",
    data,
  });
};
